package framework.base;

import framework.config.RequestCode;
import framework.config.ResultCode;
import framework.database.callback.DBCallBack;
import framework.http.bean.HttpTask;
import framework.http.callback.HttpCallBack;
import framework.jiekou.Act;
import framework.jiekou.OnClick;
import framework.jiekou.sub.ActImpl;
import framework.manage.ManageAct;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

public abstract class BaseAct extends Activity implements OnClickListener, OnClick, DBCallBack, HttpCallBack, Act {
	protected ManageAct actManager;
	private Act act;

	// ///////////////////////////////////////////////////////////////////////

	@Override
	public void onClick(View v) {
		getAct().onClick(v);
	}

	/***************************************************
	 * 
	 * 返回按钮默认事件
	 * 
	 ***************************************************/
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		return onKeyDownBackNormal(keyCode, event);
	}

	public boolean onKeyDownBackNormal(int keyCode, KeyEvent event) {
		return getAct().onKeyDownBackNormal(keyCode, event) ? true : super.onKeyDown(keyCode, event);
	}

	public boolean onKeyDownBackExit(int keyCode, KeyEvent event) {
		return getAct().onKeyDownBackExit(keyCode, event) ? true : super.onKeyDown(keyCode, event);
	}

	/***************************************************
	 * 
	 * view的显示与隐藏
	 * 
	 ***************************************************/

	public void viewShowOrHidden(View view) {
		getAct().viewShowOrHidden(view);
	}

	public boolean isVisible(View view) {
		return getAct().isVisible(view);
	}

	public void viewVisible(View view, boolean isVisible) {
		getAct().viewVisible(view, isVisible);
	}

	public void viewVisible(View view, int id, boolean isVisible) {
		getAct().viewVisible(view, id, isVisible);
	}

	public void viewShow(int id, View itemView) {
		getAct().viewShow(id, itemView);
	}

	public void viewShow(View view) {
		getAct().viewShow(view);
	}

	public void viewShow(int id) {
		getAct().viewShow(id);
	}

	public void viewGone(int id, View itemView) {
		getAct().viewGone(id, itemView);
	}

	public void viewGone(View view) {
		getAct().viewGone(view);
	}

	public void viewGone(int id) {
		getAct().viewGone(id);
	}

	/***************************************************
	 * 
	 * 一些获取View的方法
	 * 
	 ***************************************************/

	public LinearLayout findLinearLayoutById(int id) {
		return getAct().findLinearLayoutById(id);
	}

	public LinearLayout findLinearLayoutById(int id, View view) {
		return getAct().findLinearLayoutById(id, view);
	}

	public ListView findListViewById(int id) {
		return getAct().findListViewById(id);
	}

	public ListView findListViewById(int id, View view) {
		return getAct().findListViewById(id, view);
	}

	public Button findButtonById(int id) {
		return getAct().findButtonById(id);
	}

	public Button findButtonById(int id, View view) {
		return getAct().findButtonById(id, view);
	}

	public ProgressBar findProgressBarById(int id) {
		return getAct().findProgressBarById(id);
	}

	public ProgressBar findProgressBarById(int id, View view) {
		return getAct().findProgressBarById(id, view);
	}

	public ImageView findImageViewById(int id) {
		return getAct().findImageViewById(id);
	}

	public ImageView findImageViewById(int id, View view) {
		return getAct().findImageViewById(id, view);
	}

	public RelativeLayout findRelativeLayoutById(int id) {
		return getAct().findRelativeLayoutById(id);
	}

	public RelativeLayout findRelativeLayoutById(int id, View view) {
		return getAct().findRelativeLayoutById(id, view);
	}

	public TextView findTextViewById(int id) {
		return getAct().findTextViewById(id);
	}

	public TextView findTextViewById(int id, View view) {
		return getAct().findTextViewById(id, view);
	}

	public CheckBox findCheckBoxById(int id) {
		return getAct().findCheckBoxById(id);
	}

	public CheckBox findCheckBoxById(int id, View view) {
		return getAct().findCheckBoxById(id, view);
	}

	public FrameLayout findFrameLayoutById(int id) {
		return getAct().findFrameLayoutById(id);
	}

	public FrameLayout findFrameLayoutById(int id, View view) {
		return getAct().findFrameLayoutById(id, view);
	}

	public ImageButton findImageButtonById(int id) {
		return getAct().findImageButtonById(id);
	}

	public ImageButton findImageButtonById(int id, View view) {
		return getAct().findImageButtonById(id, view);
	}

	public EditText findEditTextById(int id) {
		return getAct().findEditTextById(id);
	}

	public EditText findEditTextById(int id, View view) {
		return getAct().findEditTextById(id, view);
	}

	/***************************************************
	 * 
	 * 为控件设置文字
	 * 
	 ***************************************************/

	public void setText(TextView tv, String str) {
		getAct().setText(tv, str);
	}

	public void setText(TextView tv, Object obj) {
		getAct().setText(tv, obj);
	}

	/***************************************************
	 * 
	 * 打印信息
	 * 
	 ***************************************************/
	@Override
	public void log(String msg) {
		getAct().log(msg);
	}

	@Override
	public void log(Object msg) {
		getAct().log(msg);
	}

	@Override
	public void isNull(String name, Object obj) {
		getAct().isNull(name, obj);
	}

	@Override
	public void exception(Exception e) {
		getAct().exception(e);
	}

	/***************************************************
	 * 
	 * toast方法
	 * 
	 ***************************************************/
	public void toast(String msg) {
		getAct().toast(msg);
	}

	@Override
	public void toast(int resID) {
		getAct().toast(resID);
	}

	/***************************************************
	 * 
	 * 退出程序
	 * 
	 ***************************************************/
	public void alertExit() {
		getAct().alertExit();
	}

	/***************************************************
	 * 
	 * 设置点击
	 * 
	 ***************************************************/

	@Override
	public void setClick(int viewID) {
		getAct().setClick(viewID);
	}

	@Override
	public void setClick(int viewID, View view) {
		getAct().setClick(viewID, view);
	}

	@Override
	public void setClick(View view) {
		getAct().setClick(view);
	}

	/***************************************************
	 * 
	 * 输入法隐藏或出现
	 * 
	 ***************************************************/
	public void inputHidden(EditText et) {
		getAct().inputHidden(et);
	}

	public void inputShow(EditText et) {
		getAct().inputShow(et);
	}

	/***************************************************
	 * 
	 * closeAct
	 * 
	 ***************************************************/

	public void closeAct() {
		getAct().closeAct();
	}

	public void closeActForResultOk() {
		getAct().closeActForResultOk();
	}

	public void closeActForResultCanceled() {
		getAct().closeActForResultCanceled();
	}

	public void closeActForResultError() {
		getAct().closeActForResultError();
	}

	public void closeActForResultOk(Intent data) {
		getAct().closeActForResultOk(data);
	}

	public void closeAct(int resultCode) {
		getAct().closeAct(resultCode);
	}

	public void closeAct(int resultCode, Intent data) {
		getAct().closeAct(resultCode, data);
	}

	/***************************************************
	 * 
	 * openAnim
	 * 
	 ***************************************************/

	public void animAlpha() {
		getAct().animAlpha();
	}

	public void animScaleOpen() {
		getAct().animScaleOpen();
	}

	public void animScaleClose() {
		getAct().animScaleClose();
	}

	public void animTranslateTopIn() {
		getAct().animTranslateTopIn();
	}

	public void animTranslateBottomIn() {
		getAct().animTranslateBottomIn();
	}

	public void animTranslateRightIn() {
		getAct().animTranslateRightIn();
	}

	public void animTranslateLeftIn() {
		getAct().animTranslateLeftIn();
	}

	/***************************************************
	 * 
	 * openAct
	 * 
	 ***************************************************/

	public void openAct(Intent intent) {
		getAct().openAct(intent);
	}

	public void openAct(Class newActClass) {
		getAct().openAct(newActClass);
	}

	public void openActForResult(Class newActClass, int requestCode) {
		getAct().openActForResult(newActClass, requestCode);
	}

	public void openActForResult(Intent intent, int requestCode) {
		getAct().openActForResult(intent, requestCode);
	}

	@Override
	public void openActForResult(Class newActClass, RequestCode code) {
		getAct().openActForResult(newActClass, code);
	}

	@Override
	public void openActForResult(Intent intent, RequestCode code) {
		getAct().openActForResult(intent, code);
	}

	/***************************************************
	 * 
	 * httpCallBack
	 * 
	 ***************************************************/

	@Override
	public void httpTaskFinish(HttpTask task) {
		getAct().httpTaskFinish(task);
	}

	@Override
	public void onHttpCallBack(HttpTask task) {
		getAct().onHttpCallBack(task);
	}

	/***************************************************
	 * 
	 * dbTaskFinish
	 * 
	 ***************************************************/

	@Override
	public void dbTaskFinish(int dbTaskType, Object data) {
		getAct().dbTaskFinish(dbTaskType, data);
	}

	@Override
	public void onDbCallBack(int dbTaskType, Object data) {
		getAct().onDbCallBack(dbTaskType, data);
	}

	/***************************************************
	 * 
	 * 进度条处理
	 * 
	 ***************************************************/

	public AlertDialog getAlertDialog() {
		return getAct().getAlertDialog();
	}

	public void dialogCancel(AlertDialog dialog) {
		getAct().dialogCancel(dialog);
	}

	/***************************************************
	 * 
	 * 布局设置方法
	 * 
	 ***************************************************/

	// 设置布局 及各种view注入、点击监听。
	@Override
	public void setContentView(int layoutResID) {
		getAct().setContentView(layoutResID);
	}

	@Override
	public void setContentView(View view) {
		super.setContentView(view);
		getAct().setContentView(view);
	}

	@Override
	public void setContentView(View view, ViewGroup.LayoutParams params) {
		super.setContentView(view, params);
		getAct().setContentView(view, params);
	}

	// 新的布局注入
	public void setLayout(int layoutResID) {
		getAct().setLayout(layoutResID);
	}

	/***************************************************
	 * 
	 * onCreate方法和他的替代方法
	 * 
	 ***************************************************/

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getAct().onCreateAct(savedInstanceState);
	}

	// 替代onCreate方法
	@Override
	public void onCreateAct(Bundle savedInstanceState) {

	}

	// @Override
	// public SparseArray<Method> getMethods() {
	// return getAct().getMethods();
	// }

	/***************************************************
	 * 
	 * onStart方法和他的替代方法
	 * 
	 ***************************************************/

	// onStart
	@Override
	public void onStart() {
		super.onStart();
		getAct().onStartAct();
	}

	// 替代onStart方法
	@Override
	public void onStartAct() {
	}

	/***************************************************
	 * 
	 * onResume方法和他的替代方法
	 * 
	 ***************************************************/

	@Override
	public void onResume() {
		super.onResume();
		getAct().onResumeAct();
	}

	@Override
	public void onResumeAct() {
	}

	// 恢复暂时储存的数据
	@Override
	public void onDateRecovery() {
	}

	/***************************************************
	 * 
	 * onRestart方法和他的替代方法
	 * 
	 ***************************************************/

	@Override
	public void onRestart() {
		super.onRestart();
		getAct().onRestartAct();
	}

	@Override
	public void onRestartAct() {
	}

	/***************************************************
	 * 
	 * onPause方法和他的替代方法
	 * 
	 ***************************************************/

	@Override
	public void onPause() {
		super.onPause();
		getAct().onPauseAct();
	}

	@Override
	public void onPauseAct() {
	}

	@Override
	public void onDateClear() {
	}

	/***************************************************
	 * 
	 * onStop方法和他的替代方法
	 * 
	 ***************************************************/

	@Override
	public void onStop() {
		super.onStop();
		getAct().onStopAct();
	}

	@Override
	public void onStopAct() {
	}

	/***************************************************
	 * 
	 * onDestroy方法和他的替代方法
	 * 
	 ***************************************************/

	@Override
	public void onDestroy() {
		super.onDestroy();
		getAct().onDestroyAct();

	}

	@Override
	public void onDestroyAct() {
	}

	/***************************************************
	 * 
	 * 获取AlertDialogBuilder
	 * 
	 ***************************************************/
	@Override
	public Builder getAlertDialogBuilder() {
		return getAct().getAlertDialogBuilder();
	}

	/***************************************************
	 * 
	 * 获取HttpCallBack
	 * 
	 ***************************************************/

	@Override
	public HttpCallBack getHttpCallBack() {
		return this;
	}

	/***************************************************
	 * 
	 * 获取HttpCallBack
	 * 
	 ***************************************************/

	@Override
	public DBCallBack getDBCallBack() {
		return this;
	}

	/***************************************************
	 * 
	 * 获取Activity
	 * 
	 ***************************************************/

	@Override
	public OnClickListener getOnClickListener() {
		return this;
	}

	/***************************************************
	 * 
	 * 获取Activity
	 * 
	 ***************************************************/

	@Override
	public Activity getActivity() {
		return this;
	}

	/***************************************************
	 * 
	 * 获取Act
	 * 
	 ***************************************************/

	@Override
	public Act getAct() {
		if (act == null) {
			act = new ActImpl(this, getContext());
		}

		if (act.getContext() == null) {
			act.setContext(getContext());
		}

		if (act.getAct() == null) {
			act.setAct(this);
		}

		return act;
	}

	@Override
	public void setAct(Act act) {

	}

	/***************************************************
	 * 
	 * 获取applicationContext
	 * 
	 ***************************************************/

	@Override
	public Context getContext() {
		return getApplicationContext();
	}

	@Override
	public void setContext(Context context) {
	}

	/***************************************************
	 * 
	 * 获得布局
	 * 
	 ***************************************************/

	@Override
	public View inflate(int resourceId) {
		return getAct().inflate(resourceId);
	}

	@Override
	public void layoutSetting(ViewGroup ll) {
		getAct().layoutSetting(ll);
	}

	@Override
	public void measureView(View child) {
		getAct().measureView(child);
	}

	@Override
	public void adjustTextView(TextView tv) {
		getAct().adjustTextView(tv);

	}

	/***************************************************
	 * 
	 * 设置ImageView
	 * 
	 ***************************************************/

	@Override
	public void setImageView(ImageView imageView, String url, int defaultId) {
		getAct().setImageView(imageView, url, defaultId);
	}

	/***************************************************
	 * 
	 * 获取适配后的尺寸
	 * 
	 ***************************************************/
	@Override
	public int layoutAdjustSize(int getW) {
		return getAct().layoutAdjustSize(getW);
	}

	@Override
	public Float layoutAdjustSize(Float getW) {
		return getAct().layoutAdjustSize(getW);
	}

	@Override
	public int adjustSize(int ori) {
		return getAct().adjustSize(ori);
	}

	@Override
	public int getScreenWidth() {
		return getAct().getScreenWidth();
	}

	@Override
	public int getScreenHight() {
		return getAct().getScreenHight();
	}

	@Override
	public int getDesignWidth() {
		return getAct().getDesignWidth();
	}

	@Override
	public float getDensity() {
		return getAct().getDensity();
	}

	/***************************************************
	 * 
	 * resultcode
	 * 
	 ***************************************************/

	@Override
	public int resultOk() {
		return getAct().resultOk();
	}

	@Override
	public int resultError() {
		return getAct().resultError();
	}

	@Override
	public int resultCancel() {
		return getAct().resultCancel();
	}

	@Override
	public int resultDelete() {
		return getAct().resultDelete();
	}

	@Override
	public RequestCode requestCode(int requestCode) {
		return getAct().requestCode(requestCode);
	}

	@Override
	public ResultCode resultCode(int resultCode) {
		return getAct().resultCode(resultCode);
	}

	/***************************************************
	 * 
	 * hasNet
	 * 
	 ***************************************************/
	@Override
	public boolean hasNet() {
		return getAct().hasNet();
	}

	@Override
	public void toastNoNet() {
		getAct().toastNoNet();
	}

}
